<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
class System extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->verify_user();
	}

	public function index()
	{
		$d = $this->db->get('system')->row_array();
		$this->view('system', $d);
	}

	public function update()
	{
		$name = $this->input->post('name');
		$title = $this->input->post('title');
		$keyword = $this->input->post('keyword');
		$description = $this->input->post('description');
		$copyright = $this->input->post('copyright');
		$icp = $this->input->post('icp');
		$address = $this->input->post('address');
		$phone = $this->input->post('phone');
		$qq = $this->input->post('qq');
		$qun = $this->input->post('qun');
		$logo = $this->input->post('logo');
		$en_name = $this->input->post('en_name');
		$en_title = $this->input->post('en_title');
		$en_keyword = $this->input->post('en_keyword');
		$en_description = $this->input->post('en_description');
		$en_address = $this->input->post('en_address');
		$intro = $this->input->post('intro');
		$en_intro = $this->input->post('en_intro');
		$tel = $this->input->post('tel');
		$email = $this->input->post('email');
		$weixin = $this->input->post('weixin');
		$mobile_username = $this->input->post('mobile_username');
		$mobile_password = $this->input->post('mobile_password');
		$mobile_apikey = $this->input->post('mobile_apikey');
		$data = array('name' => $name, 'title' => $title, 'keyword' => $keyword, 'description' => $description, 'copyright' => $copyright, 'icp' => $icp, 'address' => $address, 'phone' => $phone, 'qq' => $qq, 'qun' => $qun, 'en_name' => $en_name, 'en_title' => $en_title, 'en_keyword' => $en_keyword, 'en_description' => $en_description, 'en_address' => $en_address, 'intro' => $intro, 'en_intro' => $en_intro, 'tel' => $tel, 'email' => $email, 'weixin' => $weixin, 'mobile_username' => $mobile_username, 'mobile_password' => $mobile_password, 'mobile_apikey' => $mobile_apikey, 'logo' => $logo);

		if ($this->db->update('system', $data)) {
			echo json_encode(array('msg' => '修改成功', 'error' => 0));
		}
		else {
			echo json_encode(array('msg' => '修改失败', 'error' => 1));
		}
	}

	public function upload()
	{
		$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/upload/system/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = 5000;
		$config['file_name'] = rand(1000, 9999) . time();
		$this->load->library('upload', $config);

		if (!$this->upload->do_upload('Filedata')) {
			$data['error'] = 1;
			$data['msg'] = '上传失败';
		}
		else {
			$data['error'] = 0;
			$data['msg'] = '上传成功';
			$d = $this->upload->data();
			$data['file_name'] = $d['file_name'];
		}

		echo json_encode($data);
	}
}

?>
